package avicit.im.lantop.archiveplanmanager.archiveplanedit.service.api;

import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class ArchivePlanServiceApi {

    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/im/lantop/archiveplanmanager/archiveplanedit/action/rest/ArchivePlanServiceRest";

    @Autowired
    private RestClient restClient;


    /**
     * 迁移节点
     * @param param
     * @return
     */
    public Map<String, Object> moveNode(Map<String, Object> param) {
        String url = BASE_PATH + "/moveNode";
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, param, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     *
     * @param id
     * @return
     */
    public List<TreeNode> findChildsByNodeId(String id) {
        String url = BASE_PATH + "/findChildsByNodeId";
        ResponseMsg<List<TreeNode>> responseMsg = restClient.doPost(SERVICE_CODE, url, id, new ParameterizedTypeReference<ResponseMsg<List<TreeNode>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
